<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Click'N'Gage - Create New Question</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" href="css/style.css" type="text/css" />
    </h:head>
    <h:body>
        <div id="container">
            <div id="wrapper">
                <div id="top">
                    <ui:include src="WEB-INF/includes/login.xhtml"/>
                </div>

                <ui:include src="WEB-INF/includes/navigation.xhtml"/>

                <div id="header">
                    <ui:include src="WEB-INF/includes/header.xhtml"/>
                </div>
                <div id="content">
                    <h1>Create Question Form</h1>
                    <h:form>
                        <h:panelGrid columns="1">
                            <label>Course:</label>
                            <h:selectOneMenu value="#{questionManagedBean.courseID}">
                                <f:selectItems value="#{questionManagedBean.coursesTaught}"
                                               var="course"
                                               itemLabel="#{course.name} (#{course.code})"
                                               itemValue="#{course.id}"/>
                            </h:selectOneMenu>
                            <label>Question:</label>
                            <h:inputTextarea cols="50" rows="6" value="#{questionManagedBean.questionText}"/>
                            <label>Tags:</label>
                            <h:inputText value="#{questionManagedBean.tagString}" size="42"/>
                            <label>Chart Type:</label>
                            <h:selectOneRadio value="#{questionManagedBean.chartType}">
                                <f:selectItem itemLabel="Pie" itemValue="PIE" />
                                <f:selectItem itemLabel="Pie 3D" itemValue="PIE3D" />
                                <f:selectItem itemLabel="Bar" itemValue="BAR" />
                                <f:selectItem itemLabel="Bar 3D" itemValue="BAR3D" />
                                <f:selectItem itemLabel="Line" itemValue="LINE" />
                            </h:selectOneRadio>
                            <label>Possible Answers:</label>
                        </h:panelGrid>

                        <h:panelGrid columns="3">
                            <label>A</label>
                            <h:inputText value="#{questionManagedBean.answer1}" size="40"/>
                            <h:panelGroup/>

                            <label>B</label>
                            <h:inputText value="#{questionManagedBean.answer2}" size="40"/>
                            <h:panelGroup/>

                            <h:outputText value="C" rendered="#{questionManagedBean.shownAnswers >= 3}"/>
                            <h:inputText value="#{questionManagedBean.answer3}" size="40" rendered="#{questionManagedBean.shownAnswers >= 3}"/>
                            <h:commandLink action="#{questionManagedBean.deleteAnswerActionHandler}" value="[x]" rendered="#{questionManagedBean.shownAnswers == 3}">
                                <f:ajax render="@form"/>
                            </h:commandLink>
                            <h:panelGroup rendered="#{questionManagedBean.shownAnswers > 3}"/>

                            <h:outputText value="D" rendered="#{questionManagedBean.shownAnswers >= 4}"/>
                            <h:inputText value="#{questionManagedBean.answer4}" size="40" rendered="#{questionManagedBean.shownAnswers >= 4}"/>
                            <h:commandLink action="#{questionManagedBean.deleteAnswerActionHandler}" value="[x]" rendered="#{questionManagedBean.shownAnswers == 4}">
                                <f:ajax render="@form"/>
                            </h:commandLink>
                            <h:panelGroup rendered="#{questionManagedBean.shownAnswers > 4}"/>

                            <h:outputText value="E" rendered="#{questionManagedBean.shownAnswers >= 5}"/>
                            <h:inputText value="#{questionManagedBean.answer5}" size="40" rendered="#{questionManagedBean.shownAnswers >= 5}"/>
                            <h:commandLink action="#{questionManagedBean.deleteAnswerActionHandler}" value="[x]" rendered="#{questionManagedBean.shownAnswers == 5}">
                                <f:ajax render="@form"/>
                            </h:commandLink>
                            <h:panelGroup rendered="#{questionManagedBean.shownAnswers > 5}"/>

                            <h:outputText value="F" rendered="#{questionManagedBean.shownAnswers >= 6}"/>
                            <h:inputText value="#{questionManagedBean.answer6}" size="40" rendered="#{questionManagedBean.shownAnswers >= 6}"/>
                            <h:commandLink action="#{questionManagedBean.deleteAnswerActionHandler}" value="[x]" rendered="#{questionManagedBean.shownAnswers == 6}">
                                <f:ajax render="@form"/>
                            </h:commandLink>
                        </h:panelGrid>

                        <h:panelGrid columns="2">
                            <h:outputText value="Correct Answer:"/>
                            <h:selectOneMenu value="#{questionManagedBean.correctAnswer}">
                                <f:selectItems value="#{questionManagedBean.correctAnswersSelectItems}"/>
                            </h:selectOneMenu>
                        </h:panelGrid>
                        <h:panelGrid columns="1">
                            <h:commandLink value="Add another answer" action="#{questionManagedBean.addAnswerActionHandler}" rendered="#{questionManagedBean.shownAnswers != 6}">
                                <f:ajax event="action" render="@form" execute="@form"/>
                            </h:commandLink>
                            <h:commandButton value="Create" action="#{questionManagedBean.createQuestionActionHandler}" />
                        </h:panelGrid>
                        <br /><br/>
                        <h:messages styleClass="error" />
                        <h:outputText value="#{questionManagedBean.errorMessage}" styleClass="error" rendered="#{questionManagedBean.errorMessage != null}"/>
                    </h:form>
                </div>
                <div id="sidebar">
                    <h2>Quick Links</h2>
                    <ui:include src="WEB-INF/includes/quicklinks.xhtml"/>
                    <h2>Downloads</h2>
                    <ui:include src="WEB-INF/includes/download.xhtml"/>
                    <h2>Advertisments</h2>
                    <ui:include src="WEB-INF/includes/adsense.xhtml"/>
                </div>
                <div id="footer">
                    <ui:include src="WEB-INF/includes/footer.xhtml"/>
                </div>
            </div>
        </div>
    </h:body>
</html>